import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'
import { MessageBox } from 'element-ui'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-user/'

/**
 * 查询所有用户类型
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const query = (successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userType/query', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据id查询用户类别信息，主要是名称
 * @param {BigInteger} id 用户类别id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryById = (id, successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userType/queryById', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据用户id数组查询用户类别信息
 * @param {Array} ids 用户id数组
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryByIds = (ids, successCallback = null, fullCallback = null) => {
  if (!ids || ids.length === 0) {
    MessageBox.alert('ids参数为空', '请求异常', {
      confirmButtonText: '确定',
      type: 'error',
      callback: () => {
      }
    }).then(() => {})
    return
  }
  const params = {
    ids: ids
  }
  return fallbackRequestPost(URL_PREFIX + 'userType/queryByIds', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据用户类别名称查询用户类别信息，主要是通过名称获取对应的id作为上传参数
 * @param {String} name 用户类别名称
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryByName = (name, successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userType/queryByName', params, {}, true, successCallback, null, fullCallback)
}
